package autoupdate.test;


public class VersionNumber{
	private int major;
	private int minor;
	private int build;
	
	public VersionNumber(String versionString){
		String[] splitString = versionString.split("\\.");
		major = Integer.parseInt(splitString[0]);
		minor = Integer.parseInt(splitString[1]);
		build = Integer.parseInt(splitString[2]);
	}

	/**
	 * Compare two versions
	 * return > 0 if this version is a newer version than parameter version
	 * return < 0 if this version is an older version than parameter version
	 * return 0 if this version is the same version as parameter version
	 * 
	 * @param version
	 * @return
	 */
	public int compareTo(VersionNumber version){
		if(this.getMajor() > version.getMajor()){
			return 1;
		}
		else if(this.getMajor() < version.getMajor()){
			return -1;
		}
		else{
			if(this.getMinor() > version.getMinor()){
				return 1;
			}
			else if(this.getMinor() < version.getMinor()){
				return -1;
			}
			else{
				if(this.getBuild() > version.getBuild()){
					return 1;
				}
				else if(this.getBuild() < version.getBuild()){
					return -1;
				}
				else{
					return 0;
				}
			}
		}
	}

	public int getBuild(){
		return build;
	}

	public int getMajor(){
		return major;
	}

	public int getMinor(){
		return minor;
	}

	@Override
	public String toString(){
		StringBuffer strBuf = new StringBuffer();
		strBuf.append(getMajor());
		strBuf.append(".");
		strBuf.append(getMinor());
		strBuf.append(".");
		strBuf.append(getBuild());
		
		return strBuf.toString();
	}
}
